package org.example.rubbish.service.impl;


import org.example.rubbish.entity.PriceConfig;
import org.example.rubbish.mapper.PriceConfigMapper;
import org.example.rubbish.service.PriceConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class PriceConfigServiceImpl implements PriceConfigService {
    @Autowired
    private PriceConfigMapper priceConfigMapper;

    @Override
    public PriceConfig updatePriceConfig(PriceConfig config) {
        PriceConfig latest = priceConfigMapper.selectLatest();
        if (latest != null) {
            config.setId(latest.getId());
            priceConfigMapper.update(config);
        } else {
            priceConfigMapper.insert(config);
        }
        return priceConfigMapper.selectLatest();
    }

    @Override
    public PriceConfig getLatestPriceConfig() {
        return priceConfigMapper.selectLatest();
    }
}
